/*
Run this script on:

        mssql-tl-test.db.jwan.it,14444.TTTLINES2014_test    -  This database will be modified

to synchronize it with:

        kalgan01.cs.jwan.it,1443.Jambo2014_sviluppo

You are recommended to back up your database before running this script

Script created by SQL Compare version 9.0.0 from Red Gate Software Ltd at 02/04/2014 12:36:13

*/
SET NUMERIC_ROUNDABORT OFF
GO
SET ANSI_PADDING, ANSI_WARNINGS, CONCAT_NULL_YIELDS_NULL, ARITHABORT, QUOTED_IDENTIFIER, ANSI_NULLS ON
GO
IF EXISTS (SELECT * FROM tempdb..sysobjects WHERE id=OBJECT_ID('tempdb..#tmpErrors')) DROP TABLE #tmpErrors
GO
CREATE TABLE #tmpErrors (Error int)
GO
SET XACT_ABORT ON
GO
SET TRANSACTION ISOLATION LEVEL SERIALIZABLE
GO
BEGIN TRANSACTION
GO
PRINT N'Dropping constraints from [dbo].[configtasse]'
GO
ALTER TABLE [dbo].[configtasse] DROP CONSTRAINT [PK_configtasse]
GO
IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
GO

IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
GO
PRINT N'Altering [dbo].[configtasse]'
GO
ALTER TABLE [dbo].[configtasse] ALTER COLUMN [CODLOCALE] [char] (4) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL
GO
IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
GO
PRINT N'Creating primary key [PK_configtasse] on [dbo].[configtasse]'
GO
ALTER TABLE [dbo].[configtasse] ADD CONSTRAINT [PK_configtasse] PRIMARY KEY CLUSTERED  ([CODTASSA], [CODVAL], [CODITINERA], [CATKEY], [VALIDO_DAL], [VALIDO_AL], [CODSCO], [CODLIST], [CODTAR], [CODLOCALE])
GO
IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
GO
PRINT N'Adding foreign keys to [dbo].[jb_postazioniStampe]'
GO
ALTER TABLE [dbo].[jb_postazioniStampe] ADD
CONSTRAINT [FK_jb_postazioniStampe_jb_stampe] FOREIGN KEY ([CODICE_STAMPA]) REFERENCES [dbo].[jb_stampe] ([CODICE_STAMPA])
GO
IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
GO
PRINT N'Adding foreign keys to [dbo].[jb_remote_abbonamenti_passaggi]'
GO
ALTER TABLE [dbo].[jb_remote_abbonamenti_passaggi] ADD
CONSTRAINT [FK_jb_remote_abbonamenti_passaggi_jb_tessere] FOREIGN KEY ([ID_TESSERA]) REFERENCES [dbo].[jb_tessere] ([ID_TESSERA])
GO
IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
GO
IF EXISTS (SELECT * FROM #tmpErrors) ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT>0 BEGIN
PRINT 'The database update succeeded'
COMMIT TRANSACTION
END
ELSE PRINT 'The database update failed'
GO
DROP TABLE #tmpErrors
GO
